package com.atguigu.cloud.response;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<T> {

    private String code;
    private String msg;
    private T data;
    private long timestamp;

    public Result() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultEnum.RC200.getCode())
                .setMsg(ResultEnum.RC200.getMsg())
                .setData(data);
        return result;
    }

    public static <T> Result<T> fail(ResultEnum rc){
        Result<T> result = new Result<>();
        result.setCode(rc.getCode())
                .setMsg(rc.getMsg())
                .setData(null);
        return result;
    }

}
